package com.example.demo.entity.response.repository;

import com.example.demo.common.entity.response.BaseResponse;
import com.example.demo.entity.pojo.repository.RepositoryPoJo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * 仓库响应对象.
 *
 * @author Mei Ruoxiao
 * @since 2020/9/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel("仓库响应对象")
public class RepositoryResponse extends BaseResponse {

    @ApiModelProperty(value = "名称", required = true, example = "芯片仓库")
    private String name;

    @ApiModelProperty(value = "父节点ID, 默认1", example = "1")
    private Long parentId;

    @ApiModelProperty(value = "文件夹类型 0-材料 1-成品 2-废品", example = "0")
    private int type;

    public static RepositoryResponse of(final RepositoryPoJo poJo) {
        RepositoryResponse response = new RepositoryResponse();
        if (Objects.isNull(poJo)) {
            return response;
        }
        // 将 Domain 对象转换成 Response 对象
        BeanUtils.copyProperties(poJo, response);
        return response;
    }

}
